package com.airnews.ticket.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.airnews.ticket.R;

/**
 * 长按航班列表显示更多价格处理
 * @author luoxz
 *
 */
public class FlyMoreListViewAdapter extends SimpleAdapter  {
	LayoutInflater layoutInflater ;
	List<Map<String, Object>> items;

	public FlyMoreListViewAdapter(Context context, List<Map<String, Object>> items, int resource, String[] from, int[] to) {   
		super(context, items, resource, from, to);   
		layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
	}  
	
	public FlyMoreListViewAdapter(Context context, List<Map<String, Object>> items) { 
		super(context, items, 0, null, null);   
		this.items = items;
		this.layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
	}  
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		  ViewHolder holder; 
		 //得到自己定义的List的界面
		  if (convertView == null) { 
			  convertView = this.layoutInflater.inflate(R.layout.fly_row_more, null); 
			  holder = new ViewHolder(); 
			  //更多的价钱项
			  holder.priceSmall = (TextView) convertView.findViewById(R.id.priceSmall); 
			  holder.basePriceSmall = (TextView) convertView.findViewById(R.id.basePriceSmall); 
			  holder.seatSmall = (TextView) convertView.findViewById(R.id.seatSmall); 
			  holder.baseCabinSmall = (TextView) convertView.findViewById(R.id.baseCabinSmall); 
			  
			  convertView.setTag(holder); 
		  } else {
			  holder = (ViewHolder) convertView.getTag(); 
		  }
		  Log.i("FlyMoreListViewAdapter items size ", String.valueOf(items.size()));
		  holder.priceSmall.setText(this.items.get(position).get("priceSmall").toString());
		  holder.basePriceSmall.setText(this.items.get(position).get("basePriceSmall").toString());
		  holder.baseCabinSmall.setText(this.items.get(position).get("baseCabinSmall").toString());
		  String seatValue = this.items.get(position).get("seatSmall").toString();
		  if(seatValue.indexOf(">9")!=-1) {
			  holder.seatSmall.setVisibility(View.INVISIBLE);
		  } else {
			  holder.seatSmall.setText("票少");
			  holder.seatSmall.setVisibility(View.VISIBLE);
		  }
		  
		  return convertView;

	}
	
	static class ViewHolder { 
		TextView basePriceSmall,priceSmall,cabinPriceSmall,baseCabinSmall,seatSmall; 
	} 


}
